package com.googlecode.curvedmetromaps.core.model.importer;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ImportUtil {

	public static float parseCoordinate(String coord) {
		Pattern coordPattern = Pattern.compile("(?<coord>\\d+(\\.\\d+)?)");
		Matcher coordMatcher = coordPattern.matcher(coord);
		float result = 0;
		for (float div = 1f; coordMatcher.find(); div *= 60f) {
			String match = coordMatcher.group("coord");
			float part = Float.valueOf(match);
			result += part / div;
		}
		return result;
	}

	public static int parseColor(String[] rgb) {
		int c = 0;
		for (int i = 0; i < rgb.length; i++) {
			c <<= 8;
			c |= Long.decode(rgb[i]).intValue();
		}
		c |= 0xFF000000;
		return c;
	}

	public static int parseColor(String rgb) {
		int c = Long.decode(rgb).intValue();
		if (rgb.length() <= 7) {
			c |= 0xFF000000;
		}
		return c;
	}

}
